package com.boilerCloud.controller.order;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.boilerCloud.dataSource.LogAnnotation;
import com.boilerCloud.dto.HzlqswPage;
import com.boilerCloud.dto.msg.PushMessages;
import com.boilerCloud.dto.order.SalesOrder;
import com.boilerCloud.dto.sys.ReqResult;
import com.boilerCloud.service.log.ILogService;
import com.boilerCloud.service.msg.IPushService;
import com.boilerCloud.service.order.IOrderService;



@RestController
@RequestMapping("/order/")
public class OrderControler {
	private static final Logger log = LoggerFactory.getLogger(OrderControler.class);
	@Resource
	private IOrderService service;

	
	@RequestMapping(value = "unAcceptOrderList")
	public ModelAndView unAceptorder() {
		return new ModelAndView("/views/order/unAceptorder.html");
	}
	
	
	@RequestMapping(value = "acceptOrderList")
	public ModelAndView acceptOrderList() {
		return new ModelAndView("/views/order/acceptOrderList.html");
	}
	
	
	@RequestMapping(value = "overOrderList")
	public ModelAndView overOrderList() {
		return new ModelAndView("/views/order/overOrderList.html");
	}

	/**
	 * 查询订单列表
	 * @param grade
	 * @param yema
	 * @param length
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "qryOrderList", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult qryDeviceList(@ModelAttribute SalesOrder order ,
			@RequestParam(required = true) int yema,
			@RequestParam(required = true) int length,HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			
			HzlqswPage<SalesOrder> page = new HzlqswPage<SalesOrder>();
			page.setCurPage(yema);
			page.setPageSize(length);
			service.qryList(order,page);
			rst.setReturnObject(page);
			rst.setResultCode(ReqResult.resultCode_Success);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("查询订单列表失败");
			log.error("查询订单列表异常",e);
			return rst;
		}
	}
	
	
	/**
	 * 新增订单
	 * @param device
	 * @param request
	 * @return
	 */
	@LogAnnotation("新增订单")
	@RequestMapping(value = "addSalesOrder", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult addSalesOrder(
			@ModelAttribute SalesOrder order ,
			HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			service.addSalesOrder(order);
			rst.setResultCode(ReqResult.resultCode_Success);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("新增订单信息失败");
			log.error("新增订单信息异常",e);
			return rst;
		}
	}
	
	
	
	@LogAnnotation("处理订单")
	@RequestMapping(value = "handleSalesOrder", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult handleSalesOrder(
			@ModelAttribute SalesOrder order ,
			HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			service.handleSalesOrder(order);
			rst.setResultCode(ReqResult.resultCode_Success);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("新增订单信息失败");
			log.error("新增订单信息异常",e);
			return rst;
		}
	}
	
	/**
	 * 获取订单信息
	 * @param id
	 * @param request
	 * @return
	 */
	/*@RequestMapping(value = "getDeviceInfo", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult getDeviceInfo(
			@RequestParam(required = true) int id,
			HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			DeviceInfo device  = service.getDeviceInfo(id);
			rst.setResultCode(ReqResult.resultCode_Success);
			rst.setReturnObject(device);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("删除订单失败");
			log.error("删除订单异常",e);
			return rst;
		}
	}*/
	


	

	

}
